<?php
	/**
	* Show Video Page
	* 
	* @author trungdt
	* @since Oct 17, 2011
	*/
	if (!defined('EXPONENT')) exit('');
	
	// get selected cat
	$cat=null;
	$sql_where="";
	if (isset($_REQUEST['cat_name']))
	{
		$cat=_ab_safe_html_string($_REQUEST['cat_name']);
		$cat=$db->selectObject("productsmodule_video_cat", "seo_name = '{$cat}'");
		if ($cat)
		{
			$loc=unserialize($cat->location_data);
			$sql_where=" AND (cat_id = {$cat->id})";
		}
	}   
	
	$temp=serialize($loc);
	
	
	
	// get module config
	$config=$db->selectObject("productsmodule_config", "location_data = '{$temp}'");
	
	$cats=$db->selectObjects("productsmodule_video_cat", "location_data = '{$temp}'");
	
	// get all new video for playlist
	$video=$db->selectObjects("productsmodule_video","location_data = '{$temp}'  {$sql_where} ORDER BY postdate DESC LIMIT 0, 15");
		
	$video=productsmodule::__VideoProcess($video);
    
	
	$new_video=$db->selectObjects("productsmodule_video","location_data = '{$temp}' {$sql_where} ORDER BY postdate DESC LIMIT 0, 4");
	$new_video=productsmodule::__VideoProcess($new_video);
	
	$highlighted_video=$db->selectObjects("productsmodule_video","location_data = '{$temp}' {$sql_where} AND highlighted=1 ORDER BY postdate DESC LIMIT 0, 4");
	$highlighted_video=productsmodule::__VideoProcess($highlighted_video);
	
	$prior_video=$db->selectObjects("productsmodule_video","location_data = '{$temp}' AND prior=1 {$sql_where} ORDER BY postdate DESC LIMIT 0, 4");
	$prior_video=productsmodule::__VideoProcess($prior_video);
	
	// fetch to template
	$template=new template("productsmodule","_Video_Default",$loc);
	$template->register_permissions(array('administrate',"configure", "create", "edit", "delete"),$loc);
	$template->assign("cats", $cats);
	$template->assign("selected_cat", $cat);
	$template->assign("video", $video);
	$template->assign("video_count", count($video));
	// for playlist in bottom
	$template->assign("new_video", $new_video);
	$template->assign("new_video_count", count($new_video));
	
	$template->assign("highlighted_video", $highlighted_video);
	$template->assign("highlighted_video_count", count($highlighted_video));
	
	$template->assign("prior_video", $prior_video);
	$template->assign("prior_video_count", count($prior_video));
	$template->output();
	
	// 
	// to commnunicate with facebook, the only way that we must return og_meta
	// this is the reason we add video_name
    if (isset($cat->title))
    {
        _ab_theme_action_register_title($cat->title);
        _ab_theme_action_register_title($cat->search_des,1,0);
    }
	if (isset($_REQUEST['video_name']))
	{
		$ivideo=_ab_safe_html_string($_REQUEST['video_name']);
		$ivideo=$db->selectObject("productsmodule_video", "seo_name = '{$ivideo}'");
		if ($ivideo)
		{
			$ivideo=productsmodule::__VideoProcess($ivideo);
            _ab_theme_action_register_title($ivideo[0]->title." - ".$cat->title);
            _ab_theme_action_register_title($ivideo[0]->search_des,1,0);
            
			_ab_theme_og_meta_set($ivideo[0]->search_des,0);
			_ab_theme_og_meta_set($ivideo[0]->title." - ".SITE_TITLE,1);
			_ab_theme_og_meta_set($ivideo[0]->thumbnail,2);
		}
	}
?>
